#include<stdio.h>
#include<assert.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
int my_atoi(const char* str)
{
	assert(str);
	if (*str == '\0')
	{
		return 0;
	}
	while (isspace(*str))
	{
		str++;
	}
	int flag = 1;
	if (*str == '+')
	{
		flag = 1;
		str++;
	}
	else if (*str == '-')
	{
		flag = -1;
		str++;
	}
	long long ret = 0;
	while (*str != '\0')
	{
		if (isdigit(*str))
		{
			ret = ret * 10 + flag * (*str - '0');
			if (ret > INT_MAX || ret < INT_MIN)
			{
				return flag==1?INT_MAX:INT_MIN;
			}
		}
		else
		{
			return (int)ret;
		}
		str++;
	}
	return (int)ret;
}
void* my_memcpy(void* dest, const void* src, size_t num)
{
	assert(dest && src);
	void* ret = dest;
	while (num--)
	{
		*(char*)dest = *(char*)src;
		dest = (char*)dest + 1;
		src = (char*)src + 1;
	}
	return ret;
}
void* my_memmove(void* dest, const void* src, size_t num)
{
	assert(dest && src);
	void* ret = dest;
	if (dest < src)
	{
		while (num--)
		{
			*(char*)dest = *(char*)src;
			dest = (char*)dest + 1;
			src = (char*)src + 1;
		}
	}
	else
	{
		while (num--)
		{
			*((char*)dest + num) = *((char*)src + num);
		}
	}
	return ret;
}
void test01()
{
	char s1[20] = "abcdef";
	char s2[] = "   +-";
	char s3[] = "+";
	char s4[] = "-";
	char s5[] = " -+12";
	char s6[] = " 12";
	char s7[] = " +13";
	char s8[] = "+2147483647";
	char s9[] = "-2147483648";
	char s10[] = "+2147483650";
	char s11[] = "-2147483650";
	printf("%d\n", my_atoi(s1));
	printf("%d\n", my_atoi(s2));
	printf("%d\n", my_atoi(s3));
	printf("%d\n", my_atoi(s4));
	printf("%d\n", my_atoi(s5));
	printf("%d\n", my_atoi(s6));
	printf("%d\n", my_atoi(s7));
	printf("%d\n", my_atoi(s8));
	printf("%d\n", my_atoi(s9));
	printf("%d\n", my_atoi(s10));
	printf("%d\n", my_atoi(s11));
}
void test02()
{
	char s1[] = "abcdefg";
	char s2[] = "xyz";
	my_memcpy(s1, s2, 3);
	printf("%s\n",s1);
	char s3[] = "jklmno";
	my_memmove(s1, s3, 6);
	printf("%s\n",s1);
}
int main()
{
	test01();
	test02();
	return 0;
}